import 'package:flutter/material.dart';

class StateControlView  extends StatefulWidget {
  const StateControlView({ super.key });

  @override
  State<StateControlView> createState() => __StateControlView();
}

// 定义状态在私有类中定义
class __StateControlView extends State<StateControlView> {
  int count = 0;
  String name = "123";
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
           ElevatedButton(
           onPressed: () {
            setState(() {
             count--;
            });
            // 所有的框架前端 渲染都是异步的！！！！ 不可能同步
           
           },
           child: const Text('减'),
          ),
          Text(count.toString(), style: const TextStyle(fontSize: 50.0)),
          ElevatedButton(
           onPressed: () {
            setState(() {
                count++;  // 数据更新完成后 => 驱动UI更新
            });
          
           },
           child: const Text('加'),
          ),
          Text(name),
           ElevatedButton(
           onPressed: () {
            setState(() {
                name = "老高";  // 数据更新完成后 => 驱动UI更新
            });
          
           },
           child: const Text('加'),
          )
        ],
       )
    );
  }
}